#override("css")
<link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
#end

#override("body")
<body class="white-bg">
<form id="baseForm"  class="form-horizontal m-t" autocomplete="off" data-validator-option="{timely:2, theme:'default', focusCleanup:true}">
	<div class="wrapper wrapper-content animated fadeInRight form-item">
		<div class="panel panel-default">
			<div class="tabs-container">
				<ul class="nav nav-tabs">
					<li class="active"><a data-toggle="tab" href="#tab-base">基本信息</a></li>
					<li class=""><a data-toggle="tab" href="#tab-declare">字段列表</a></li>
				</ul>

				<div class="tab-content ">
					<div id="tab-base" class="tab-pane active">
						<div class="panel-body">
							<div class="row">
								<div class="col-sm-12">
									<div class="ibox float-e-margins">
										<div class="ibox-content">
											<div class="panel-body">
												<input type="hidden" name="id" value="$!{genTable.id}">

												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-md-2 control-label">所属类型:</label>
														<div class="col-md-8">
															<input type=text id="categoryName" name="categoryName" class="form-control" value="$!{genTable.categoryName}" onclick="showDialog()" readonly="readonly" data-rule="所属类型:required">
															<input type="hidden" id="categoryValue" name="categoryValue" value="$!{genTable.categoryValue}">
															<span class="help-inline">请选择需要配置的表所属的表类型</span>
														</div>
													</div>
												</div>
												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-md-2 control-label">表名:</label>
														<div class="col-md-8">
															<input type="text" class="form-control" id="tableName" name="tableName" maxlength="200" value="$!{genTable.tableName}" readonly="readonly" data-rule="表名:required">
															<span class="help-inline">数据库表名</span>
														</div>
													</div>
												</div>
												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-md-2 control-label">类名:</label>
														<div class="col-md-8">
															<input type="text" class="form-control" name="className" maxlength="200" value="$!{genTable.className}" data-rule="类名:required">
															<span class="help-inline">数据库表生成对应的实体类名(相关的dao、service、controller类等都以这个名称为前缀)</span>
														</div>
													</div>
												</div>
												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-md-2 control-label">生成FO表:</label>
														<div class="col-md-8">
															<div class="radio i-checks">
																<label><input type="radio" name="createFo" value="0" #if($!genTable.createFo eq '0') checked="" #else '' #end data-rule="checked"><i></i>不生成</label>
																<label><input type="radio" name="createFo" value="1" #if($!genTable.createFo eq '1') checked="" #else '' #end> <i></i>生成</label>
																<span class="help-inline">&nbsp;&nbsp;&nbsp;&nbsp;当前为TP表,生成对应的FO表</span>
															</div>
														</div>
													</div>
												</div>
												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-md-2 control-label">生成AR表:</label>
														<div class="col-md-8">
															<div class="radio i-checks">
																<label><input type="radio" name="createAr" value="0" #if($!genTable.createAr eq '0') checked="" #else '' #end data-rule="checked"><i></i>不生成</label>
																<label><input type="radio" name="createAr" value="1" #if($!genTable.createAr eq '1') checked="" #else '' #end> <i></i>生成</label>
																<span class="help-inline">&nbsp;&nbsp;&nbsp;&nbsp;当前为TP表,生成对应的AR表</span>
															</div>
														</div>
													</div>
												</div>
												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-md-2 control-label">说明:</label>
														<div class="col-md-10">
															<textarea class="form-control" name="comments" placeholder="请输入表的说明信息" data-rule="length(~200)">$!{genTable.comments}</textarea>
															<span class="form-inline">数据库表的说明(此说明会作为生成的文件的说明信息)</span>
														</div>
													</div>
												</div>
												<div class="col-xs-6">
													<div class="form-group">
														<label class="col-md-4 control-label">父表表名:</label>
														<div class="col-md-8">
															<select class="form-control" name="parentTable">
																<option value="">无</option>
																#foreach($!table in $!tableList)
																<option value="$!table.tableName">$!table.tableName:$!table.comments</option>
																#end
															</select>
															<span class="help-inline">如果有父表，请指定父表表名和外键</span>
														</div>
													</div>
												</div>
												<div class="col-xs-6">
													<div class="form-group">
														<label class="col-md-4 control-label">当前表外键:</label>
														<div class="col-md-8">
															<select class="form-control" name="parentTableFk">
																<option value="">无</option>
																#foreach($column in $genTable.columnList)
																<option value="$column.columnName">$column.columnName:$column.comments</option>
																#end
															</select>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div id="tab-declare" class="tab-pane">
						<div class="panel-body">
							<div class="row">
								<div class="col-sm-12">
									<div class="ibox float-e-margins">
										<div class="ibox-content">
											<div class="table-responsive">
												<table class="table table-bordered table-striped">
													<thead>
														<tr>
															<th title="数据库字段名">列名</th>
															<th title="默认读取数据库字段备注">说明</th>
															<th title="数据库中设置的字段类型及长度">物理类型</th>
															<th title="实体对象的属性字段类型">Java类型</th>
															<th title="实体对象的属性字段（对象名.属性名|属性名2|属性名3，例如：用户user.id|name|loginName，属性名2和属性名3为Join时关联查询的字段）">
																Java属性名称 <i class="icon-question-sign"></i></th>
															<th title="是否是数据库主键">主键</th>
															<th title="字段是否可为空值，不可为空字段自动进行空值验证">可空</th>
															<th title="选中后该字段被加入到insert语句里">插入</th>
															<th title="选中后该字段被加入到update语句里">编辑</th>
															<th title="选中后该字段被加入到查询列表里">列表</th>
															<th title="选中后该字段被加入到查询条件里">查询</th>
															<th title="该字段为查询字段时的查询匹配放松">查询匹配方式</th>
															<th title="字段在表单中显示的类型">显示表单类型</th>
															<th title="显示表单类型设置为“下拉框、复选框、点选框”时，需设置字典的类型">字典类型</th>
															<th>排序</th>
														</tr>
													</thead>
													<tbody>
													#set ($i=0)
													#foreach($column in $genTable.columnList)
													#set($i=$i+1)
														<tr #if($column.delFlag eq '1') class="error" title="已删除的列，保存之后消失！" #else '' #end>
															<td>
																<input type="hidden" name="columnList[$i].id" value="$!{column.id}"/>
																<input type="hidden" name="columnList[$i].delFlag" value="$!{column.delFlag}"/>
																<input type="hidden" name="columnList[$i].genTable.id" value="$!{column.genTable.id}"/>
																<input type="hidden" name="columnList[$i].baseJavaType" value="$!{column.baseJavaType}"/>
																<input type="hidden" name="columnList[$i].baseJavaField" value="$!{column.baseJavaField}"/>
																<input type="hidden" class="form-control" name="columnList[$i].columnName" value="$!{column.columnName}"/>$!{column.columnName}
															</td>
															<td>
																<input type="text" class="form-control" name="columnList[$i].comments" value="$!{column.comments}" maxlength="200" data-rule="required"/>
															</td>
															<td>
																<input type="hidden" name="columnList[$i].jdbcType" value="$!{column.jdbcType}"/>$!{column.jdbcType}
															</td>
															<td>
																<select class="form-control" name="columnList[$i].javaType" style="width:85px;*width:75px" data-rule="checked">
																	#foreach($dict in $config.javaTypeList)
																	<option value="$dict.value" #if($dict.value eq $column.javaType) selected #else '' #end>$!{dict.label}</option>
																	#end
																</select>
															</td>
															<td>
																<input type="text" class="form-control" name="columnList[$i].javaField" value="$!{column.javaField}" maxlength="200" data-rule="required"/>
															</td>
															<td>
																<input type="checkbox" name="columnList[$i].isPk" value="1" #if($column.isPk eq '1') checked #else '' #end/>
															</td>
															<td>
																<input type="checkbox" name="columnList[$i].isNull" value="1" #if($column.isNull eq '1') checked #else '' #end/>
															</td>
															<td>
																<input type="checkbox" name="columnList[$i].isInsert" value="1" #if($column.isInsert eq '1') checked #else '' #end/>
															</td>
															<td>
																<input type="checkbox" name="columnList[$i].isEdit" value="1" #if($column.isEdit eq '1') checked #else '' #end/>
															</td>
															<td>
																<input type="checkbox" name="columnList[$i].isList" value="1" #if($column.isList eq '1') checked #else '' #end/>
															</td>
															<td>
																<input type="checkbox" name="columnList[$i].isQuery" value="1"  #if($column.isQuery eq '1') checked #else '' #end/>
															</td>
															<td>
																<select class="form-control" name="columnList[$i].queryType" class="required input-mini" data-rule="checked">
																	#foreach($dict in $config.queryTypeList)
																	<option value="$dict.value" #if($dict.value eq $column.queryType) selected #else '' #end>$!{dict.label}</option>
																	#end
																</select>
															</td>
															<td>
																<select class="form-control" name="columnList[$i].showType" class="required input-mini" data-rule="checked">
																	#foreach($dict in $config.showTypeList)
																	<option value="$dict.value" #if($dict.value eq $column.showType) selected #else '' #end>$!{dict.label}</option>
																	#end
																</select>
															</td>
															<td>
																<input type="text" class="form-control" name="columnList[$i].dictType" maxlength="200" value="$!{column.dictType}"/>
															</td>
															<td>
																<input type="number" class="form-control required input-min digits" name="columnList[$i].sort" maxlength="3" value="$!{column.sort}" data-rule="required"/>
															</td>
														</tr>
													#end
													</tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
</body>
#end

#override("js")
<script type="text/javascript">
	// 页面加载的时候调用的js
	$(function () {
		if ("$!{action}" == "doView") {
			$('input,select,textarea,checkbox,radio', $('form[id="baseForm"]')).attr('disabled', true);
		}
	});

	$("#baseForm").validator({
		valid: function (form) {
			var me = this;
			// 提交表单之前，hold住表单，防止重复提交
			me.holdSubmit();

			$.ajax({
				url: "#springUrl('/gen/genTable/doEdit')",
				data: $(form).serialize(),
				type: "POST",
				success: function (data) {
					if (data.success) {
						parent.refreshTable(); 					// 重新刷新父页面
						parent.layer.alert('处理数据成功', {icon: 1}, function () {
							parent.layer.closeAll();
						});
					} else {
						parent.layer.alert(data.message, {icon: 2}, function (index) {
							//失败,提交表单成功后,释放hold,如果不释放hold,就变成了只能提交一次的表单
							me.holdSubmit(false);
							parent.layer.close(index);
						});
					}
				}
			});
		}
	});
	// 调用方法实现保存
	function save() {
		// 手工触发表单验证
		$("#baseForm").trigger('validate');
	}

	/* 转到显示选择表类型树页面 */
	function showDialog() {
		var currentId = $("#categoryValue").val();
		var url = "#springUrl('/gen/genTable/toTableCategory?currentId="+currentId+"')";
		layer_show_btn("选择数据表类型", url, 400, null);
	}
</script>
#end
#extends("/common/base.html")